<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    div{
        text-align: center;
    }
    img{
        vertical-align: top;
    }
    .ss{
     position: fixed;
     top: 0;
     left: 50%;
     transform: translateX(-50% );
    }
    .xia{
margin-top: 10px;
    }
</style>

<body>
    <div class="box">
        <img src="./imgs/top.png" alt="">
    </div>
    <div class="zhong">
        <img src="./imgs/nav.png" alt="">
    </div>
    <div class="xia">
        <img src="./imgs/main.png" alt="">
    </div>
</body>
<script>
    var box=document.querySelector('.box')
    var zhong=document.querySelector('.zhong')
    var h = box.offsetHeight
    // console.log('h='+ h)
    window.onscroll = function(){
            // console.log(window.pageYOffset);
            var scrollY = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop || 0
            if(scrollY>=h){
                zhong.className ='ss'
            }else{
                zhong.className = ''
            }
        }
    

</script>
</html>